package org.tangdao.modules.file.model.domain;

import java.io.Serializable;

import org.tangdao.common.config.Global;
import org.tangdao.common.io.FileUtils;
import org.tangdao.common.lang.ByteUtils;
import org.tangdao.modules.file.model.vo.FileUploadParams;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Getter;
import lombok.Setter;

/**
 * @ClassName: FileEntity
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author RuYang
 * @date 2019/03/07
 * 
 */
@Getter
@Setter
@TableName("sys_file_entity")
public class FileEntity implements Serializable {

	private static final long serialVersionUID = 1L; // 序列

	@TableId
	private String fileId; // 文件编号

	private String fileMd5; // 文件MD5

	private String filePath; // 文件相对路径

	private String fileContentType; // 文件内容类型

	private String fileExtension; // 文件后缀扩展名

	private Long fileSize; // 文件大小(单位B)

	@TableField(exist = false)
	private String status;

	@TableField(exist = false)
	private FileUploadParams fileUploadParams;

	public FileEntity() {
		super();
	}

	public String getFileSizeFormat() {
		if (this.fileSize == null) {
			return null;
		}
		return ByteUtils.formatByteSize(this.fileSize);
	}

	@JsonIgnore
	public String getFileRealPath() {
		return Global.getUserfilesBaseDir(FileUploadParams.FILEUPLOAD_BASE_URL + "/" + this.filePath + "/")
				+ this.fileId + "." + this.fileExtension;
	}

	@JsonIgnore
	public String getFileUrl() {
		return FileUtils
				.path(Global.USERFILES_BASE_URL + FileUploadParams.FILEUPLOAD_BASE_URL + "/" + this.filePath + "/")
				+ this.fileId + "." + this.fileExtension;
	}

}
